#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2017/5/18 21:38
# @Author  : Beam
# @File    : rabbitmq-广播模式之fanout-publisher.py

import pika,sys

credentials = pika.PlainCredentials('admin', 'admin')   #设置rabbitmq连接账号密码，默认是guest，guest
connection = pika.BlockingConnection(pika.ConnectionParameters('192.168.6.248',5672,'/',credentials))
channel = connection.channel()   #建立连接通道

channel.exchange_declare(exchange='logs',type='fanout')   #设置广播模式，类型是fanout
message = ' '.join(sys.argv[1:]) or "info: Hello World!"
channel.basic_publish(exchange="logs",    #定义exchange 值要跟上面的对应
                      routing_key="",      #因为是广播模式，所以队列名没有意义
                      body=message)
print(" [x] Sent %r" % message)
connection.close()

